package com.reins.bookstore.object;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.reins.bookstore.entity.OrderItem;
import com.reins.bookstore.entity.Orders;
import lombok.Data;

@Data
public class OrderDTO {

    private int orderId;    // 订单编号
    private int userId;     // 用户id
    private Date orderTime; //订单时间
    private BigDecimal totalorderCost;  // 总价格
    private List<BasketlineDTO> totalorder_books = new LinkedList<>(); //书籍列表
    public OrderDTO(int orderId, int userId, BigDecimal totalorderCost, List<BasketlineDTO> totalorder_books){
        this.orderId = orderId;
        this.userId = userId;
        this.totalorderCost = totalorderCost;
        this.totalorder_books = totalorder_books;
    }
    public OrderDTO(Orders orders, BigDecimal totalorderCost, List<BasketlineDTO> totalorder_books){
        this.orderId = orders.getOrderId();
        this.userId = orders.getUserId();
        this.userId = orders.getUserAuth().getUserId();
        this.orderTime = orders.getOrderTime();
        this.totalorderCost = totalorderCost;
        this.totalorder_books = totalorder_books;
    }
    public OrderDTO() {
    }

    // 用一个Orders来直接初始化一个OrderDTO
    public OrderDTO(Orders orders){
        this.orderId = orders.getOrderId();
        this.userId = orders.getUserId();
        this.orderTime = orders.getOrderTime();
        totalorderCost = new BigDecimal(0);
        // 直接遍历，然后赋值进去
        for (OrderItem one_item : orders.getOrderlines()){
            BasketlineDTO add_bas = new BasketlineDTO(one_item.getBook(),one_item.getBookNum());
            totalorder_books.add(add_bas);
            BigDecimal add_cost = one_item.getListCost();
            totalorderCost.add(add_cost);
        }
    }

    public BigDecimal getTotalorderCost() {
        return totalorderCost;
    }
}
